package com.ruoyi.web.controller.teacher;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teacher.domain.SysTeacher;
import com.ruoyi.teacher.service.ISysTeacherService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * sysTeacherController
 * @author ruoyi
 * @date 2022-01-13
 */
@Controller
@RequestMapping("/teacher/teacher")
public class SysTeacherController extends BaseController
{
    private String prefix = "teacher/teacher";

    @Autowired
    private ISysTeacherService sysTeacherService;

    @RequiresPermissions("teacher:teacher:view")
    @GetMapping()
    public String teacher()
    {
        return prefix + "/teacher";
    }

    /**
     * 查询sysTeacher列表
     */
    @RequiresPermissions("teacher:teacher:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysTeacher sysTeacher)
    {
        startPage();
        List<SysTeacher> list = sysTeacherService.selectSysTeacherList(sysTeacher);
        return getDataTable(list);
    }

    /**
     * 新增sysTeacher
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存sysTeacher
     */
    @RequiresPermissions("teacher:teacher:add")
    @Log(title = "sysTeacher", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysTeacher sysTeacher)
    {
        sysTeacher.setCreateBy(getLoginName());
        return toAjax(sysTeacherService.insertSysTeacher(sysTeacher));
    }

    /**
     * 修改sysTeacher
     */
    @RequiresPermissions("teacher:teacher:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysTeacher sysTeacher = sysTeacherService.selectSysTeacherById(id);
        mmap.put("sysTeacher", sysTeacher);
        return prefix + "/edit";
    }

    /**
     * 修改保存sysTeacher
     */
    @RequiresPermissions("teacher:teacher:edit")
    @Log(title = "sysTeacher", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysTeacher sysTeacher)
    {
        sysTeacher.setUpdateBy(getLoginName());
        return toAjax(sysTeacherService.updateSysTeacher(sysTeacher));
    }

    /**
     * 删除sysTeacher
     */
    @RequiresPermissions("teacher:teacher:remove")
    @Log(title = "sysTeacher", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysTeacherService.deleteSysTeacherByIds(ids));
    }


/*
    */
/**
     * 校验用户名
     *//*

    @PostMapping("/checkCardUnique")
    @ResponseBody
    public String checkCardUnique(SysTeacher sysTeacher)
    {
        return sysTeacherService.checkCardUnique(sysTeacher.getCard());
    }

    @PostMapping("/checkTeacherIdUnique")
    @ResponseBody
    public String checkTeacherIdUnique(SysTeacher sysTeacher)
    {
        return sysTeacherService.checkTeacherIdUnique(sysTeacher.getTeacherId());
    }
*/


}
